package com.xywy.tangandroid.util;



	import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.telephony.TelephonyManager;
import android.view.Display;
import android.view.WindowManager;

	/**
	 * ���ڻ�ȡ�绰�豸��Ϣ
	 * 
	 * @author mz  ��Ҫ����Ȩ��<uses-permission
	 *         android:name="android.permission.READ_PHONE_STATE"/>
	 */
	public class DeviceUtil {
		private static TelephonyManager telephonyManager;

		/**
		 * ��ȡ�ֻ��ͺ�
		 * 
		 * @return
		 */
		public static String getPhoneModel(Context context) {
			if (telephonyManager == null)
				telephonyManager = (TelephonyManager) context
						.getSystemService(Context.TELEPHONY_SERVICE);
			return android.os.Build.MODEL;
		}

		/**
		 * ��ȡ�ֻ�����
		 * 
		 * @return
		 */
		public static String getPhoneManufacturer(Context context) {
			if (telephonyManager == null)
				telephonyManager = (TelephonyManager) context
						.getSystemService(Context.TELEPHONY_SERVICE);
			return android.os.Build.MANUFACTURER;
		}

		/**
		 * ��ȡ�ֻ��ֱ���
		 * 
		 * @return
		 */
		public static String getPhoneDisplay(Context context) {
			Display display = ((WindowManager) context
					.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
			int width = display.getWidth();
			int height = display.getHeight();
			return width + "*" + height;
		}

		/**
		 * ��ȡ��ǰapp�汾��.���ǰ汾����
		 * 
		 * @return
		 */
		public static String getAppVersionCode(Context context) {

			PackageManager packageManager = context.getPackageManager();
			// getPackageName()���㵱ǰ��İ�����0�����ǻ�ȡ�汾��Ϣ
			PackageInfo packInfo = null;
			try {
				packInfo = packageManager.getPackageInfo(context.getPackageName(),
						0);
			} catch (NameNotFoundException e) {
				e.printStackTrace();
				return null;
			}
			return packInfo.versionCode + "";
		}

		/**
		 * ��ȡ��ǰapp�汾����.
		 * 
		 * @return
		 */
		public static String getAppVersionName(Context context) {

			PackageManager packageManager = context.getPackageManager();
			// getPackageName()���㵱ǰ��İ�����0�����ǻ�ȡ�汾��Ϣ
			PackageInfo packInfo = null;
			try {
				packInfo = packageManager.getPackageInfo(context.getPackageName(),
						0);
			} catch (NameNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
			return packInfo.versionName + "";
		}


		/**
		 * ��ȡ��Ļ�Ŀ�
		 * @param activity
		 * @return
		 */
		public static int getDeviceWidth(Activity activity) {
			Display display = activity.getWindowManager().getDefaultDisplay();
			return display.getWidth();
		}

		/**
		 * ��ȡ��Ļ�ĸ�
		 * @param activity
		 * @return
		 */
		public static int getDeviceHeight(Activity activity) {
			Display display = activity.getWindowManager().getDefaultDisplay();
			return display.getHeight();
		}
		
		/**
		 * ��ȡ֪ͨ���ĸ߶�
		 * @return
		 */
		public static int getNoticeBarHeight() {
			return Resources.getSystem().getDimensionPixelSize(
					Resources.getSystem().getIdentifier("status_bar_height",
							"dimen", "android"));
		}
		

	}


